﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using Castle.ActiveRecord;
using NHibernate.Criterion;
using LIB;
using System.Collections;

public partial class admin_system_Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            int id = ConvertUtility.ToInt32(Request.QueryString["id"]);
            if (id > 0)
            {
                pnGioiThieu.Visible = false;
                pnModule.Visible = true;
                int catID = ConvertUtility.ToInt32(Request.QueryString["id"]);
                hidCatID.Value = catID.ToString();
                Category_Info catInfo = Category_Info.Find(catID);
                if (catInfo != null)
                {
                    litPos.Text = "<a href='/admin/system/default.aspx'>Hệ thống</a> >>";
                    catDeQuyNguoc[] lstCat = catDeQuyNguoc.getLinkCat(catID);
                    for (int i = lstCat.Length - 1; i > -1; i--)
                    {
                        litPos.Text += "<a href='/admin/system/default.aspx?id=" + lstCat[i].id + "'> " + lstCat[i].catName + " </a> >>";
                    }
                  
                    repSubCat.DataSource = Category_Info.FindAll(Order.Asc("catOrder"), Expression.Eq("catParentID", catInfo));
                    repSubCat.DataBind();
                }
                lblMessage.Text = "";
            }
            else
            {
                litPos.Text = "Hệ thống";
                pnGioiThieu.Visible = true;
                pnModule.Visible = false;
            }
        }
        catch (Exception ex) { }
    }
    protected void btnDel_Click(object sender, EventArgs e)
    {
        try
        {
            string[] arrKeyDel = hidKeyDel.Value.Split('|');

            for (int i = 0; i < arrKeyDel.Length - 1; i++)
            {
                int catID = Convert.ToInt32(arrKeyDel[i].Trim());
                Home_Cat_Info.DeleteAll("catID=" + catID);
                Category_Info catInfo = Category_Info.Find(catID);
                catInfo.DeleteAndFlush();
            }
            Response.Redirect(HttpContext.Current.Request.Url.PathAndQuery);

        }
        catch (Exception ex)
        {
            lblMessage.Text = "Có lỗi xảy ra. Hãy thử lại";
            fail.Visible = true;
        }
    }
    protected void btnThemMoi_Click(object sender, EventArgs e)
    {
        int catID = ConvertUtility.ToInt32(Request.QueryString["id"]);
        if (catID > 0)
            Response.Redirect("/admin/system/editor.aspx?catID=" + catID);
        //else
        //    Response.Redirect("/admin/system/editor.aspx?catID=4");
    }
}